import allure
from appium.webdriver.common.appiumby import AppiumBy

from base.xueqiu_app import XueQiu
from page.manage_page import Manager
from page.set_page import SetPage


class FreePage(XueQiu):
    _all = AppiumBy.XPATH, "//*[@text='全部']"
    _set = AppiumBy.XPATH, "//*[@resource-id='com.xueqiu.android:id/portfolio_setting']"
    _new_price = AppiumBy.XPATH, "//*[@text='最新价']"
    _page = AppiumBy.XPATH, "//*[@resource-id='com.xueqiu.android:id/row_recycler']/*[@resource-id='com.xueqiu.android:id/fm_container'][1]/*[@resource-id='com.xueqiu.android:id/item_layout']"
    _manage = AppiumBy.ID, 'com.xueqiu.android:id/edit_group'

    @allure.step('全部自选股')
    def all(self):
        # 点击全部
        self.find_ele_click(self._all)
        self.screen()
        return self

    @allure.step('自选设置')
    def setting(self):
        # 点击设置
        self.find_ele_click(self._set)
        self.screen()
        return SetPage(self.driver)

    @allure.step('最新价格排序')
    def sort(self):
        # 最新价格排序
        self.find_ele_click(self._new_price)
        price = self.find_eles(self._page)
        price_list = [float(e.text) for e in price]
        self.screen()
        return price_list

    @allure.step('自选管理')
    def manage(self):
        # 管理
        self.find_ele_click(self._manage)
        self.screen()
        return Manager(self.driver)
